$(()=>{
    let $get = $("#get");
    let $inputbox = $("#inputbox");
    $inputbox.focus();
    let $main = $("#main");
    let $table = $("#table");
    /*let $item1 = $("#item1");*/
    let $item2 = $("#item2");
    let $item3 = $("#item3");
    let $item4 = $("#item4");
    let $select1 = $("#select1");
    let $select2 = $("#select2");
    let $select3 = $("#select3");
    let data;
    let pchilds;
    let cchilds;
    $inputbox.keydown(e=>{if (e.keyCode===13)$get.click();});
    $(document).keydown(e=>{if(e.keyCode===36){if (e.ctrlKey){if(confirm("是否要返回上一页？")){location.href = "./?/index";}}else{if(confirm("是否要返回首页？")){history.back();}}}else if(e.keyCode===45){$inputbox.focus();}});
    $get.click(()=>{
        $main.addClass("el-loading");
        let zone = $inputbox.val();
        $.post("#",{},text=>{
            $main.removeClass("el-loading");
            $table.hide();
            $table.removeClass("el-loading");
            data=JSON.parse(text);
            if(data.code==1){
                let x=`<option value="">--选择省--</option>`;
                for(let i=0;i<data.data.length;i++){
                    x+=`<option value="${i}">${data.data[i].name}</option>`;
                }
                $select1.html(x);
                $select1.removeAttr("disabled");
            }else{
                alert(data.msg);
            }
            /* console.log(text); */
        });
    });
    $select1.change(()=>{
        let a=$select1.val();
        pchilds=data.data[a].pchilds;
        let x=`<option value="">--选择市--</option>`;
        for(let i=0;i<pchilds.length;i++){
            x+=`<option value="${i}">${pchilds[i].name}</option>`
        }
        $select2.html(x);
        $select2.removeAttr("disabled");
    });
    $select2.change(()=>{
        let a=$select2.val();
        cchilds=pchilds[a].cchilds;
        let x=`<option value="">--选择区--</option>`;
        for(let i=0;i<cchilds.length;i++){
            x+=`<option value="${i}">${cchilds[i].name}</option>`;
        }
        $select3.html(x);
        $select3.removeAttr("disabled");
    });
    $select3.change(()=>{
        let a=$select3.val();
        if(a){
            $("#output").text(`区号：${cchilds[a].code}`);
        }else{
            $("#output").text("");
        }
    });
});
